home *** CD-ROM | disk | FTP | other *** search
/ io Programmo 53 / IOPROG_53.ISO / soft / c++ / xceedftp.exe / Samples / Visual Basic / FTPClient / clsLocalPaths.cls next >
Encoding:
Visual Basic class definition  |  2000-10-05  |  5.7 KB  |  177 lines

  1. VERSION 1.0 CLASS
  2. BEGIN
  3.   MultiUse = -1  'True
  4. END
  5. Attribute VB_Name = "clsLocalPaths"
  6. Attribute VB_GlobalNameSpace = False
  7. Attribute VB_Creatable = True
  8. Attribute VB_PredeclaredId = False
  9. Attribute VB_Exposed = False
  10. ' Xceed FTP Library - FTP Client sample application
  11. ' Copyright (c) 2000 Xceed Software Inc.
  12. '
  13. ' [clsLocalPaths.cls]
  14. '
  15. ' This class module contains code for local file/folder/drive listings and operations.
  16. '
  17. ' This file is part of the Xceed FTP Library sample applications. The source
  18. ' code in this file is only intended as a supplement to Xceed FTP Library's
  19. ' documentation, and is provided "as is", without warranty of any kind,
  20. ' either expressed or implied.
  21.  
  22. Option Explicit
  23.  
  24. ' Import a WIN32 API function we need
  25.  
  26. Private Declare Function GetLogicalDriveStrings Lib "kernel32" Alias "GetLogicalDriveStringsA" (ByVal nBufferLength As Long, ByVal lpBuffer As String) As Long
  27.  
  28. ' This class triggers the following 3 events to whoever instantiates it. So,
  29. ' when instantiating this class, use "Dim WithEvents <INSTANCENAME> as clsLocalPaths"
  30.  
  31. Event UpdateLocalEntry(ByVal sName As String, ByVal dtDate As Date, ByVal lSize As Long, ByVal nAttrib As Integer)
  32. Event AddToLocalPaths(ByVal sPathToAdd As String)
  33. Event LogicalDriveFound(ByVal sDriveToAdd As String)
  34.  
  35. ' Constants
  36.  
  37. Const MsgBoxTitle = "FTP Client sample application "
  38.  
  39. ' ****************************************************************************
  40. ' The following procedure will read the contents of the selected drive or
  41. ' folder. If the selected path is a file, the file's information will be also
  42. ' retrieved.
  43. ' ****************************************************************************
  44.  
  45. Public Sub RetrieveLocalFolderContents(ByVal sPath As String)
  46.   Dim sName As String
  47.   Dim dtDate As Date
  48.   Dim lSize As Long
  49.   Dim nAttrib As Integer
  50.  
  51.   On Error GoTo LocalError
  52.   
  53.   sName = Dir(sPath & "*", vbNormal + vbArchive + vbDirectory + vbHidden + vbReadOnly + vbSystem)
  54.     
  55.   Do While (sName <> "")
  56.     
  57.     If (sName <> ".") And (sName <> "..") Then  ' Remove the "." and ".." files
  58.       nAttrib = GetAttr(sPath & sName)          ' Retrieve the attributes
  59.       dtDate = FileDateTime(sPath & sName)      ' Retrieve the date
  60.       lSize = (FileLen(sPath & sName))          ' Retrieve the size
  61.       
  62.       ' Send the information to our main form through an event
  63.       
  64.       RaiseEvent UpdateLocalEntry(sName, dtDate, lSize, nAttrib)
  65.     End If
  66.     
  67.     sName = Dir
  68.   Loop
  69.   
  70.   RaiseEvent AddToLocalPaths(sPath)
  71.   Exit Sub
  72.   
  73. LocalError:
  74.  
  75.   Select Case Err.Number
  76.   
  77.   ' This error occurs if the attributes could not be retreived. Ex : Pagefile.sys
  78.   ' If this is the case, we will set the attribute to -1
  79.   
  80.   Case 5
  81.     nAttrib = -1
  82.     Resume Next
  83.   Case Else
  84.     Call MsgBox("Cannot read the contents of " & sPath, vbOKOnly + vbCritical, MsgBoxTitle & "[Error]")
  85.     Exit Sub
  86.   End Select
  87.   
  88. End Sub
  89.  
  90. ' ****************************************************************************
  91. ' Retrieve the logical drive names
  92. ' ****************************************************************************
  93.  
  94. Public Sub RetreiveLogicalDrives()
  95.   Dim sDrives As String * 260
  96.   Dim nFirstPos As Integer
  97.   Dim nLastPos As Integer
  98.   
  99.   On Error Resume Next
  100.   
  101.   'This function will retreive all the logical drive names
  102.   Call GetLogicalDriveStrings(260, sDrives)
  103.   
  104.   nFirstPos = 1
  105.   
  106.   'Since this functions returns only one string with all the drives letters one
  107.   'after the other, we will need to parse the string.
  108.   Do While Mid(sDrives, nFirstPos, 1) <> Chr(0)
  109.     nLastPos = nFirstPos
  110.     Do While Mid(sDrives, nLastPos, 1) <> Chr(0)
  111.       nLastPos = nLastPos + 1
  112.     Loop
  113.     
  114.     'Send the information to our main form
  115.     RaiseEvent LogicalDriveFound(Mid(sDrives, nFirstPos, nLastPos - nFirstPos))
  116.     nFirstPos = nLastPos + 1
  117.   Loop
  118. End Sub
  119.  
  120. ' ****************************************************************************
  121. ' Delete the selected local file(s)
  122. ' ****************************************************************************
  123.  
  124. Public Sub DeleteLocalFile(ByVal sFileToDelete As String)
  125.        
  126.   On Error Resume Next
  127.   
  128.   Call Kill(sFileToDelete) ' Delete the file
  129.   
  130.   If Err.Number <> 0 Then
  131.     MsgBox "Cannot delete " & sFileToDelete, vbOK + vbCritical, MsgBoxTitle & "[Notice]"
  132.   End If
  133. End Sub
  134.  
  135. ' ****************************************************************************
  136. ' Rename the selected local file
  137. ' ****************************************************************************
  138.  
  139. Public Sub RenameLocalFile(ByVal sCurrentName As String, ByVal sNewName As String)
  140.   On Error Resume Next
  141.   
  142.   Name sCurrentName As sNewName
  143.   
  144.   If Err.Number <> 0 Then
  145.     MsgBox "Cannot rename " & sCurrentName, vbOK + vbCritical, MsgBoxTitle & "[Notice]"
  146.   End If
  147. End Sub
  148.  
  149. ' ****************************************************************************
  150. ' Remove the selected local folder
  151. ' ****************************************************************************
  152.  
  153. Public Sub RemoveLocalFolder(ByVal sFolderToDelete As String)
  154.   On Error Resume Next
  155.   
  156.   Call RmDir(sFolderToDelete)
  157.     
  158.   If Err.Number <> 0 Then
  159.     MsgBox "Cannot remove " & sFolderToDelete, vbOK + vbCritical, MsgBoxTitle & "[Notice]"
  160.   End If
  161. End Sub
  162.  
  163. ' ****************************************************************************
  164. ' Create a new local folder
  165. ' ****************************************************************************
  166.  
  167. Public Sub CreateLocalFolder(ByVal sFolderToCreate As String)
  168.   On Error Resume Next
  169.   
  170.   Call MkDir(sFolderToCreate)
  171.   
  172.   If Err.Number <> 0 Then
  173.     MsgBox "Cannot create " & sFolderToCreate, vbOK + vbCritical, MsgBoxTitle & "[Notice]"
  174.   End If
  175. End Sub
  176.  
  177.